package com.atguigu.lease.admin.controller.agreement;

import com.atguigu.lease.admin.service.ViewAppointmentService;
import com.atguigu.lease.model.bean.ViewAppointment;
import com.atguigu.lease.model.dto.ViewAppointmentQueryDto;
import com.atguigu.lease.model.enums.AppointmentStatus;
import com.atguigu.lease.model.result.Response;
import com.atguigu.lease.model.vo.AppointmentItemVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "看房预约管理模块")
@RestController
@RequestMapping("/admin/appointment")
public class AppointmentController {
    @Autowired
    ViewAppointmentService viewAppointmentService;

    @Operation(summary = "2、根据id和状态修改看房预约的状态")
    @PostMapping("updateStatusById")
    public Response updateStatusById(@RequestParam Long id,
                                     @RequestParam AppointmentStatus status) {
        //自动填充：必须使用update 或者 save方法 传入 表映射的对象 才可以！！
        viewAppointmentService.update(Wrappers.lambdaUpdate(ViewAppointment.class)
                .eq(ViewAppointment::getId, id)
                .set(ViewAppointment::getAppointmentStatus, status)
        );
        return Response.ok(null);
    }

    @Operation(summary = "1、条件分页查询看房预约列表")
    @GetMapping("/page") // url?k=v&k2=v2
    public Response<Page<AppointmentItemVo>> page(ViewAppointmentQueryDto appointmentQueryDto){
        Page<AppointmentItemVo> page = viewAppointmentService.getPage(appointmentQueryDto);
        return Response.ok(page);
    }

}
